package com.telesound.dataimport.producor;

import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.telesound.dataimport.util.StringUtil;
import com.telesound.datm.dao.ICameraInfoDao;

public class CameraIdProducor  implements PkProducor{
	private ICameraInfoDao cameraInfoDao;
	
	public CameraIdProducor(){
		String classPath=Thread.currentThread().getContextClassLoader().getResource("").getPath();
		ApplicationContext ac = new FileSystemXmlApplicationContext(classPath+"/applicationContext.xml");
		ICameraInfoDao dao=(ICameraInfoDao)ac.getBean("ICameraInfoDao");
		this.cameraInfoDao=dao;
	}

	public String getPK(Object obj) {
		Map cameraMsg=(Map)obj;
		String loginOrgId=StringUtil.getStringValue(cameraMsg.get("org_id"));
		String minorType=StringUtil.getStringValue(cameraMsg.get("camera_minor_type"));
		String cameraIdSub=loginOrgId+".503.1."+minorType;
		String serialNum=cameraInfoDao.getCameraSerialNum(cameraIdSub, "camera_info");
		String cameraId=cameraIdSub+"."+serialNum;
		return cameraId;
	}

}
